<?
	


$objUser->email = isset($_POST["email"]) ? absolutelyEscapeString($_POST["email"]) : NULL;
$objUser->login = isset($_POST["login"]) ? absolutelyEscapeString($_POST["login"]) : NULL;
$objUser->pass1 = isset($_POST["pass1"]) ? absolutelyEscapeString($_POST["pass1"]) : NULL;
$objUser->pass2 = isset($_POST["pass2"]) ? absolutelyEscapeString($_POST["pass2"]) : NULL;
$objUser->firstName = isset($_POST["firstName"]) ? absolutelyEscapeString($_POST["firstName"]) : NULL;
$objUser->lastName = isset($_POST["lastName"]) ? absolutelyEscapeString($_POST["lastName"]) : NULL;
$objUser->birthDay_day = isset($_POST["birthDayDay"]) ? absolutelyEscapeString($_POST["birthDayDay"]) : NULL;
$objUser->birthDay_month = isset($_POST["birthDayMonth"]) ? absolutelyEscapeString($_POST["birthDayMonth"]) : NULL;
$objUser->birthDay_year = isset($_POST["birthDayYear"]) ? absolutelyEscapeString($_POST["birthDayYear"]) : NULL;
$objUser->phone = isset($_POST["phone"]) ? absolutelyEscapeString($_POST["phone"]) : NULL;
$objUser->sex = isset($_POST["sex"]) ? absolutelyEscapeString($_POST["sex"]) : NULL;
$objUser->relationshipStatus = isset($_POST["relationshipStatus_".$objUser->sex]) ? absolutelyEscapeString($_POST["relationshipStatus_".$objUser->sex]) : NULL;
$objUser->country = isset($_POST["country"]) ? absolutelyEscapeString($_POST["country"]) : NULL;
$objUser->city = isset($_POST["city"]) ? absolutelyEscapeString($_POST["city"]) : NULL;
$objUser->profession = isset($_POST["profession"]) ? absolutelyEscapeString($_POST["profession"]) : NULL;
$objUser->professionExperience = isset($_POST["professionExperience"]) ? absolutelyEscapeString($_POST["professionExperience"]) : NULL;
$objUser->regConfirmTerms = isset($_POST["regConfirmTerms"]) ? 1 : 0;

$objUser->regKcapthca = isset($_POST["regKcapthca"]) ? absolutelyEscapeString($_POST["regKcapthca"]) : NULL;


try {
	$objUser->regUserWithValidation();
        
	$objSession->logIn($objUser->email , $objUser->pswrd, 0);
	// add avatar big image
	if (isset($_FILES['photo']['name']) && $_FILES['photo']['name'] != ""){
		
		$image = new Image('file', $_FILES['photo'], array(
		'maxWidth' => 500, 
		'newExtension' => 'jpg', 
		'folder' => ABSPATH."images/avatars/", 
		'imageName' =>$objUser->getIdUser(), 
		'deleteOnChange' => false), null);
		$image->addArrSize(0, 0, 'o_'); 
		//$image->addArrSize(50, 50, 's_');
		//$image->addArrSize(650, 650, 'm_');
		
		$image->save();

                $objSession->moveTo(W_ABSPATH."edit_avatar", "Вы успешно зарегистрировались<br>Теперь необходимо отредактировать аватар<br>", 1);
	}

        header('HTTP/1.1 301 Moved Permanently');
        header('Location: '.W_ABSPATH.'profile');

	//$objSession->moveTo(W_ABSPATH."profile", "Вы успешно зарегистрировались", 1);
}
catch(Exception_Multiline $exM){
	$error = NULL;
	foreach ($exM as $eM){ //Проходим по всем исключениям
		$error .= $eM . '<br />';
	}  // Выводим отдельно взятое исключение
	
	$error .= "Не забудьте повторно ввести пароль и текст с картинки";
	User_User::setUserMessage($error, -1);
}
?>